home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 2
/
Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso
/
Aminet
/
comm
/
mail
/
ems1_0_exec.lha
/
Rexx
/
TickAction.ems
< prev
Wrap
Text File
|
1993-08-30
|
10KB
|
414 lines
/******************************************/
/* Handles file-related actions */
/******************************************/
/* */
/* Commands: */
/* */
/* UNARC */
/* CD|<directory> */
/* EXEC|<AmigaDos command> */
/* ECHO|<string> */
/* LOG|<file name>|<log line> */
/* */
/* IF|<file pattern>|<command> */
/* IFNOT|<file pattern>|<command> */
/* IFISARC|<archiver name>|<command> */
/* IFISNOTARC|<archiver name>|<command> */
/* GOTO|<label> */
/* LABEL|<label> */
/* END */
/* */
/******************************************/
/* */
/* Patterns: */
/* */
/* %fullfile */
/* %path */
/* %file */
/* %size */
/* %area */
/* %from */
/* %date */
/* %desc */
/* */
/******************************************/
/* $VER: TickAction.ems 1.0 (29.08.93) */
/******************************************/
options results
signal on syntax
parse arg opts
if( ~show( 'l', "rexxsupport.library" ) ) then
do
if( ~addlib( "rexxsupport.library", 0, -30, 0 ) )then
do
say "Could not open rexxsupport.library"
exit 10
end
end
if( ~show( 'l', "ems_rexx.library" ) ) then
do
if( ~addlib( "ems_rexx.library", 0, -30, 0 ) )then
do
say "Could not open ems_rexx.library"
exit 10
end
end
/* Save Current Directory */
saved_CD = PRAGMA( 'D' )
global_onlyimported = 'TRUE'
global_ignore_RCV = 'FALSE'
global_noEXEC = 'FALSE'
global_help = 'FALSE'
/* Parse options */
do while length( opts ) ~= 0
parse var opts opt opts; opt = upper( opt )
select
when opt = "FORCE" then global_onlyimported = 'FALSE'
when opt = "NORCV" then global_ignore_RCV = 'TRUE'
when opt = "NOEXEC" then global_noEXEC = 'TRUE'
when opt = "HELP" then global_help = 'TRUE'
otherwise nop
end
end
if global_help = 'TRUE' then
do
say "Usage: Rx TickAction.ems [options]"
say
say " options = FORCE : process all the files, not only the new ones."
say " NORCV : reprocess all the files."
say " NOEXEC : don't apply EXEC/LOG commands."
say " HELP : this banner."
say
signal ScriptExit
end
/* Get the required list of areas. */
if global_onlyimported = 'TRUE' then call EMS_Areas_Imported( 'areas' )
else call EMS_Areas( 'areas' )
/* Get the matching patterns */
call EMS_CustomCfg_Get( 'TickAction', '', '', 'area_patterns' )
/*
** Scan areas.
*/
do i=1 to areas.0
area_kind = upper( EMS_Area_Type( areas.i ) )
if area_kind ~= 'TICK' then iterate
if global_ignore_RCV = 'TRUE' then call EMS_Area_Item_List_Flagged( areas.i, 'MSG', 'msg', 'FATT' )
else call EMS_Area_Item_List_Flagged( areas.i, 'MSG', 'msg', '~RCV FATT' )
do j=1 to msg.0
call EMS_Item_Alloc( 'tic', areas.i, 'MSG', msg.j )
file = EMS_Item_Header_AttachedFile( 'tic' )
if file ~= '' then
do
fullfile = EMS_Area_FullFileName( areas.i, file )
if fullfile ~= '' then
do
modifiers.1 = 'fullfile'; data.1 = fullfile
modifiers.2 = 'path' ; data.2 = left( fullfile, length( fullfile ) - length( file ) )
modifiers.3 = 'file' ; data.3 = file
modifiers.4 = 'size' ; data.4 = FileSize( fullfile )
modifiers.5 = 'area' ; data.5 = areas.i
modifiers.6 = 'from' ; data.6 = EMS_Item_Header_Address_From( 'tic' )
modifiers.7 = 'date' ; data.7 = EMS_Item_Header_Date_Received( 'tic' )
modifiers.8 = 'desc' ; data.8 = EMS_Item_Line( 'tic', 'TEXT', 0 )
modifiers.0 = 8 ; data.0 = 8
dump.0 = 1
dump.1 = areas.i
do k = 1 to area_patterns.0
if EMS_Search_In_Stem( 'dump', area_patterns.k ) == 1 then
do
call PRAGMA( 'D', saved_CD ); call ExecCommands( area_patterns.k , file )
end
end
end
end
call EMS_Item_Free( 'tic' )
if global_noEXEC = 'FALSE' then call EMS_Area_Item_Flag( areas.i, 'MSG', msg.j, 'RCV', 'ON' )
end
end
ScriptExit:
/* Restore Current Directory */
call PRAGMA( 'D', saved_CD )
call EMS_FreeScriptData()
return 0
syntax:
error_text = EMS_LastError()
if error_text = '' then error_text = rc ErrorText( rc )
say '| ***BREAK: error at' sigl error_text
/* Restore Current Directory */
call PRAGMA( 'D', saved_CD )
call EMS_FreeScriptData()
exit rc
FileSize: procedure
parse arg file
status = STATEF( file )
parse var status 'FILE' size .
return size
ExecCommands: procedure EXPOSE modifiers. data. global_noEXEC
parse arg pattern , file
call EMS_CustomCfg_Get( 'TickAction', pattern, 'CMD', 'cmds' )
do i=1 to cmds.0
parse var cmds.i cmd '|' args; cmd = upper( cmd )
do forever
/*
** IF|<file pattern>|<command>
*/
if cmd = 'IF' then
do
parse var args pattern_file '|' cmd '|' args; cmd = upper( cmd )
if FileMatch( file, pattern_file ) = 1 then iterate
else leave
end
/*
** IFNOT|<file pattern>|<command>
*/
if cmd = 'IFNOT' then
do
parse var args pattern_file '|' cmd '|' args; cmd = upper( cmd )
if FileMatch( file, pattern_file ) ~= 1 then iterate
else leave
end
/*
** IFISARC|<archiver name>|<command>
*/
if cmd = 'IFISARC' then
do
parse var args arc '|' cmd '|' args; cmd = upper( cmd )
arc = upper( arc )
match = upper( EMS_Archiver_Match( data.1 ) )
if match = arc then iterate
else leave
end
/*
** IFISNOTARC|<archiver name>|<command>
*/
if cmd = 'IFISNOTARC' then
do
parse var args arc '|' cmd '|' args; cmd = upper( cmd )
arc = upper( arc )
match = upper( EMS_Archiver_Match( data.1 ) )
if match ~= arc then iterate
else leave
end
/*
** GOTO|<label>
*/
if cmd = 'GOTO' then
do
args = upper( strip( args, 'B' ) )
do j=i to cmds.0
parse var cmds.j cmd '|' label .
if upper( cmd ) ~= 'LABEL' then iterate
if upper( label ) = args then leave
end
if j <= cmds.0 then i = j - 1
else i = cmds.0
leave
end
select
/*
** UNARC
*/
when cmd = 'UNARC' then
do
if global_noEXEC = 'FALSE' then call EMS_Unarc( data.1 )
end
/*
** CD|<directory>
*/
when cmd = 'CD' then
do
line = EMS_Translate_Stem( args, 'modifiers', 'data' )
if line ~= '' then call pragma( 'D', line )
end
/*
** EXEC|<AmigaDos command>
*/
when cmd = 'EXEC' then
do
line = EMS_Translate_Stem( args, 'modifiers', 'data' )
if global_noEXEC = 'FALSE' & line ~= '' then address command line
end
/*
** ECHO|<string>
*/
when cmd = 'ECHO' then
do
line = EMS_Translate_Stem( args, 'modifiers', 'data' )
say line
end
/*
** LOG|<file name>|<log line>
*/
when cmd = 'LOG' then
do
parse var args work_file '|' args
line = EMS_Translate_Stem( args, 'modifiers', 'data' )
if global_noEXEC = 'FALSE' then
do
if work_file ~= '' then
do
if open( 'cmd_io', work_file, 'APPEND' ) ~= 1 then
do
if open( 'cmd_io', work_file, 'WRITE' ) ~= 1 then leave
end
call writeln( 'cmd_io', line )
call close( 'cmd_io' )
end
end
else
do
say 'LOG:' line
end
end
when cmd = 'END' then i = cmds.0
otherwise nop
end
leave
end
end
return 0
FileMatch: procedure
parse arg file , pattern
dump.0 = 1
dump.1 = file
return EMS_Search_In_Stem( 'dump', pattern )